package 力扣日常刷题.木22二月.第20天226;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2022/2/26
 * @description
 */
public class Demo154字符串碎片 {

    public static void main(String[] args) {
        System.out.println(GetFragment("abbccdddd"));
    }

    public static int GetFragment (String str) {
        // write code here
        int n = str.length();
        if(n == 0) return 0;
        ArrayList<Integer> lists = new ArrayList<>();
        char last = str.charAt(0);
        int i = 0,j = 1;

        for (j = 1; j < str.length(); j++) {
            if(last == str.charAt(j))continue;
            else{
                lists.add(j - i);
                i = j;
                last = str.charAt(j);
            }
        }
        lists.add(j - i);
        int sum = 0;
        for (Integer list : lists) {
            sum += list;
        }
        return sum/lists.size();
    }

}
